package com.zyf.school.manager.controller;

import com.zyf.school.manager.domain.Area;
import com.zyf.school.manager.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/area/")
public class AreaController {

    @Autowired
    private AreaService areaService;


    @RequestMapping("areaNameList")
    @ResponseBody
    //通过区域号码查询校区信息
    public List<Area> queryById(String tel) {
        System.out.println("通过" + tel + "查询数据.........................");
        List<Area> list = areaService.queryByParentTel(tel);
        return list;
    }

    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
                true));
    }
}
